﻿
package test {
	import extremefx.unitTest.Trace;
	import extremefx.events.ObjectEventArgs;
	import extremefx.events.StatusEventArgs;
	import extremefx.remoting.AmfRestRequest;
	import extremefx.remoting.WsseAuthorization;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;

	/**
	 * @author Marcelo Volmaro
	 */
	 
	[Frame(factoryClass="extremefx.Preloader")];
	public final class RestTest extends Sprite {
		
		private var _request:AmfRestRequest;
		private var _tf:TextField;
		
		public function main():void{
			var tf:TextField = _tf = new TextField();
			var tfmt:TextFormat = new TextFormat("arial unicode ms", 14, 0);
			stage.addEventListener(Event.RESIZE, resizeStage);
			addChild(tf);
			tf.x = 0;
			tf.y = 0;
			tf.width = stage.stageWidth;
			tf.height = stage.stageHeight;
			tf.defaultTextFormat = tfmt;
			
			var a:User = new User();
			a.date = new Date(),
			a.Name = "NN X";
			a.Id = 5;
			
			var r:AmfRestRequest = _request = new AmfRestRequest("http://localhost:3337/Rest.axd", "employee");
			r.setAuthorization(new WsseAuthorization("cheloxl","testpassword"));
			
			
			r.onComplete.add(_onComplete);
			r.onError.add(_onError);
			
			r.read("3");

//			r.update("5", a);
//			r.removeAll({name:"Marcelo"});
					
//			r.list({name:"Marcelo"});

//			r.insert(a);
//			
			
//			r.insert(e);
//			r.update("4", e);
		}
		
		private function _onError(pSender:AmfRestRequest, pEvent:StatusEventArgs):void {
			_trace(Trace.obj(pEvent));
		}

		private function _trace(pE:String):void {
			_tf.appendText(pE);
		}
		
		private function _onComplete(pSender:AmfRestRequest, pEvent:ObjectEventArgs):void {
			_trace(Trace.obj(pEvent.value));
		}
		
		private function resizeStage(event:Event):void {
			_tf.width = stage.stageWidth;
			_tf.height = stage.stageHeight;
		}
	}
}

import flash.net.registerClassAlias;

class User {
	registerClassAlias( "Efx.Web.Remoting.User", User );
	public var Id:int;
	public var date:Date;
	public var Name:String;
}

